import requests
import json,re

# 设置请求的日期和目标URL
date = '2024-10-09'
url = f'https://np-anotice-stock.eastmoney.com/api/security/ann?cb=jQuery112303244339797036426_1728545898701&sr=-1&page_size=100&page_index=2&ann_type=SHA%2CCYB%2CSZA%2CBJA%2CINV&client_source=web&f_node=7&s_node=0&source_type=313'

# 发送请求s
response = requests.get(url)
# 使用正则表达式去掉 jQuery 回调函数的部分
json_str = re.sub(r'^jQuery\d+_\d+\(', '', response.text)  # 去掉前面的函数名
json_str = json_str.rstrip(')')  # 去掉结尾的括号
data = json.loads(json_str)
# 打印结果
print(json.dumps(data, indent=4, ensure_ascii=False))
for record in data['data']['list']:
    if record['source_type'] == '313':
        print(record['title'])
    else:
        print(record['title'], record['source_type'],record['display_time'])
    # print(record['title'], record['title'],record['source_type'],record['display_time'])
    # print(f"股票代码: {record['codes']['stock_code']}, 股票名称: {record['codes']['short_name']}, 标题: {record['title']}, 类型: {record['source_type']}, 公告日期: {record['display_time']}")

